package Controller;

import java.io.IOException;
import java.net.Authenticator.RequestorType;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Beans.Aluno;
import Beans.Usuario;
import DAO.ArquivoDAO;
import DAO.ArquivoDAOImplementation;

/**
 * Servlet implementation class DownloadServlet
 */
@WebServlet("/DownloadServlet")
public class DownloadServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String nomeArquivo = request.getParameter("download");
		HttpSession session = request.getSession(false);
		Usuario usuario = (Usuario) session.getAttribute("Usuario");
		
		//checar senha, verificar se aruivo existe
		ArquivoDAO arquivoDAO = new ArquivoDAOImplementation();
		arquivoDAO.download(usuario, nomeArquivo);
		response.sendRedirect("Download.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
}
